package com.chis.netty.simplehttp;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 
 * @Description:编码解码
 * @Company:zwx
 * @author jw
 * @date:2015年05月11日
 */
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {
	/** 日志*/
	private static Logger LOG = LogManager.getLogger(HttpServerInitializer.class);

	@Override
	public void initChannel(SocketChannel ch) throws Exception {
		try {
			ChannelPipeline p = ch.pipeline();
			// http编解码
			p.addLast(new HttpServerCodec());
			p.addLast(new HttpObjectAggregator(10485760));
			// 业务处理
			p.addLast("handler", new HttpServerHandler());
		} catch (Exception e) {
			LOG.error(e.getMessage(), e);
			throw new Exception(e.getMessage());
		}
	}
}
